﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
namespace AlbonWeb.Admin
{
    public partial class LoginPower : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //绑定浏览器信息
                string cmdstr = "select distinct browser from CookieInfo";
                SqlHelper.BindDropDownList(ddlBrowser, "browser", "browser", SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null);
                ddlBrowser.Items.Insert(0,"-browser-");
                ViewState["limit"] = " where 1=1";
                bindCookie();
            }
        }
        //绑定Cookie信息
        protected void bindCookie()
        {
            if (userName.Text != "")
            {
                ViewState["limit"] += " and userName like '%"+userName.Text.Trim()+"%'";
            }
            if (ddlBrowser.SelectedIndex != 0)
            {
                ViewState["limit"] += " and browser='"+ddlBrowser.SelectedItem.Text+"'";
            }
            string cmdstr = "select count(*) from CookieInfo " + ViewState["limit"].ToString();
            AspNetPager1.RecordCount = int.Parse(SqlHelper.ExecuteScalar(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).ToString());
            SqlParameter[] parameters = new SqlParameter[]{
                new SqlParameter("@tablename","CookieInfo"),
                new SqlParameter("@startIndex",AspNetPager1.StartRecordIndex),
                new  SqlParameter("@endIndex",AspNetPager1.EndRecordIndex),
                new SqlParameter("@limit",ViewState["limit"].ToString()),
                new SqlParameter("@orderby","createDate desc")
            };
            SqlHelper.BindRepeater(repMain, SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "netpager", parameters);
        }

        //搜索
        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            ViewState["limit"] = " where 1=1";
            bindCookie();
        }

        //换页 
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            bindCookie();
        }

        protected void btnPass_Click(object sender, EventArgs e)
        {
            LinkButton btnPass = (LinkButton)sender;
            Albon.Model.CookieInfo cookie = new Albon.Model.CookieInfo();
            cookie.ID=int.Parse(btnPass.CommandArgument);
            cookie.Passed =! bool.Parse(btnPass.CommandName);
            BLL.CookieBLL cookiebll = new BLL.CookieBLL();
            cookiebll.setState(cookie);
            bindCookie();
        }

    }
}